package commandPatern;

import gui.abstracts.AbstractPanel;
import gui.abstracts.AbstractTable;
import gui.containerDate.Item;
import gui.panels.PanelGroup;

import java.sql.SQLException;

import javax.swing.JTable;

import bean.GroupBean;
import bean.UniversityBean;

import patern.Sybject;

import dao.UniversityDAO;

public class Insert implements Command {
	private UniversityBean university;
	private AbstractTable abstractTable;

	public Insert(UniversityBean un, AbstractTable abstractTable) {
		this.university = un;
		this.abstractTable = abstractTable;
	}

	@Override
	public void undo() throws InstantiationException, IllegalAccessException,
			ClassNotFoundException, SQLException {
		System.out.println("undo");
		UniversityDAO uDAO = university.getDAO();
		uDAO.Delet(university);
		abstractTable.getDefaultTableMOdel().removeRow(abstractTable.getRowCount() - 1);
		
		Sybject.getInstance().removeNotifyOps(new Item(((GroupBean) university).getId(),
				((GroupBean) university).getDenumire()));
	}

	@Override
	public void rendoo() throws InstantiationException, IllegalAccessException,
			ClassNotFoundException, SQLException {
		UniversityDAO uDAO = university.getDAO();
		uDAO.InsertUndoRendoo(university);

		abstractTable.getDefaultTableMOdel().insertRow(abstractTable.getRowCount(),university.getRow());
		
		Sybject.getInstance().addNotifyObs(new Item(((GroupBean) university).getId(),
				((GroupBean) university).getDenumire()));
	}

}
